﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;
using System.Reflection;

namespace Axial
{
	public class WFClass : Control
	{
		public string ClassName { get; set; }

		protected override void OnLoad(EventArgs e)
		{
			base.OnLoad(e);

			var types = from an in Page.GetType().Assembly.GetReferencedAssemblies()
						let a = Assembly.Load(an)
						from t in a.GetExportedTypes()
						where t.FullName == ClassName
						select t;
			if (types.Count() > 1)
				throw new ArgumentException("Ambiguous type " + ClassName, "typename");
			var type = types.FirstOrDefault();
			if (type == null)
				throw new ArgumentException("Can't find the type " + ClassName, "typename");
			Page.ClientScript.RegisterClientScriptBlock(typeof(WFClass), ClassName, JSWebTranslator.DissembleClass(type), true);
		}
	}
}
